﻿using NMock2.Syntax;

namespace NMock2.Internal
{
	internal class PropertyValueBuilder<T> : IAutoValueSyntax<T>
	{
		private readonly IArgumentMatcher _builder;
		private readonly bool _isIndexer;

		public PropertyValueBuilder(IArgumentMatcher builder, bool isIndexer)
		{
			_builder = builder;
			_isIndexer = isIndexer;
		}

		public ICommentSyntax To(T equalValue)
		{
			if(_isIndexer)
			{
				_builder.AddArgumentMatcher(Is.EqualTo(equalValue));
				return _builder;
			}
			return To(Is.EqualTo(equalValue));
		}

		public IMatchSyntax To(Matcher valueMatcher)
		{
			if (_isIndexer)
			{
				_builder.AddArgumentMatcher(valueMatcher);
				return _builder;
			}
			return _builder.With(valueMatcher);
		}

		public IMatchSyntax To(object equalValue)
		{
			if (_isIndexer)
			{
				_builder.AddArgumentMatcher(Is.EqualTo(equalValue));
				return _builder;
			}
			return To(Is.EqualTo(equalValue));
		}

		public ICommentSyntax ToAnything()
		{
			return _builder;
		}
	}
}
